<?php

class Silk_View_Helper_RenderAssets {

    public function setView(Zend_View_Interface $pView){
	$this->view = $pView;
    }

    public function renderAssets(){
	$html = '';

	$asset_path = Silk::get('assets');
	$assets = Zend_Registry::get('silk_cms_assets___');
	$session = new Zend_Session_Namespace('silk_cms_assets___');

	$css = array();

	foreach ($assets['stylesheets'] as $stylesheet){
	    if (file_exists($stylesheet)){
		$css_content = file_get_contents($stylesheet);

		$css[] = $css_content;
		unset($css_content);
	    }
	}

	$session->styles = $css;

	if (count($css) > 0)
	    $html .= '<link rel="stylesheet" type="text/css" href="' . $asset_path . '/styles/silk-styles.php"/>' . "\n";

	unset($css);

	$scripts = array();

	foreach ($assets['scripts'] as $script){
	    if (file_exists($script)){
		$script_content = file_get_contents($script);

		$scripts[] = $script_content;
		unset($script_content);
	    }
	}

	$session->scripts = $scripts;

	if (count($scripts) > 0)
	    $html .= '<script type="text/javascript" src="' . $asset_path . '/scripts/silk-scripts.php"></script>' ."\n";

	unset($scripts);

	unset($assets);

	return $html;
    }
}

?>